package com.youlai.system.service.impl;

import cn.hutool.core.lang.Assert;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.youlai.system.converter.SocialSecurityConverter;
import com.youlai.system.mapper.SocialSecurityMapper;
import com.youlai.system.model.entity.SocialSecurity;
import com.youlai.system.model.entity.SocialSecurity;
import com.youlai.system.model.form.SocialSecurityForm;
import com.youlai.system.model.query.SocialSecurityQuery;
import com.youlai.system.model.vo.SocialSecurityVO;
import com.youlai.system.service.SocialSecurityService;
import lombok.Data;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@Data
public class SocialSecurityServiceImpl extends ServiceImpl<SocialSecurityMapper, SocialSecurity> implements SocialSecurityService {
    private final SocialSecurityMapper socialSecurityMapper;
    private final SocialSecurityConverter socialSecurityConverter;

    @Override
    public SocialSecurityVO selectSocialSecurityAllById(Integer id) {
        SocialSecurityVO socialSecurityVO=socialSecurityMapper.selectSocialSecurityAllById(id);
        return socialSecurityVO;
    }

    @Override
    public PageInfo<SocialSecurityVO> getSocialSecurityList(SocialSecurityQuery queryParams) {
        int pageNum = queryParams.getPageNum();
        int pageSize = queryParams.getPageSize();
        Integer keyword = queryParams.getKeyword();

        PageHelper.startPage(pageNum, pageSize);
        List<SocialSecurityVO> list = socialSecurityMapper.selectSocialSecurity(keyword);

        return new PageInfo<SocialSecurityVO>(list);
    }

    @Override
    public PageInfo<SocialSecurityVO> getSocialSecurityListAll(SocialSecurityQuery queryParams) {
        int pageNum = queryParams.getPageNum();
        int pageSize = queryParams.getPageSize();
        Integer keyword = queryParams.getKeyword();

        PageHelper.startPage(pageNum, pageSize);
        List<SocialSecurityVO> list = socialSecurityMapper.selectSocialSecurityAll(keyword);

        return new PageInfo<SocialSecurityVO>(list);
    }

    @Override
    public Integer saveSocialSecurity(SocialSecurityForm socialSecurityForm) {
        SocialSecurity entity = socialSecurityConverter.form2Entity(socialSecurityForm);
        boolean result = socialSecurityMapper.saveSocialSecurity(entity);
        Assert.isTrue(result,"社保保存失败");
        return 0;
    }

    @Override
    public Integer UpdateSocialSecurity(SocialSecurityForm SocialSecurityForm) {
        SocialSecurity entity = socialSecurityConverter.form2Entity(SocialSecurityForm);
        boolean result = socialSecurityMapper.UpdateSocialSecurity(entity);
        Assert.isTrue(result,"社保修改失败");
        return 0;
    }

    @Override
    public boolean deleteByIds(String ids) {
        return false;
    }

    @Override
    public SocialSecurityForm getSocialSecurityForm(Long id) {
        return null;
    }

//        Page<SocialSecurity> socialSecurityPage = this.page(
//                new com.baomidou.mybatisplus.extension.plugins.pagination.Page<>(pageNum, pageSize),
//                new LambdaQueryWrapper<SocialSecurity>()
//                        /**
//                         * .like 模糊查询，这里就是模糊查询教师姓名
//                         * .select 就是将查询出来的信息显示出来，这里就是全显示
//                         */
//                        .like(StrUtil.isNotBlank(keyword), SocialSecurity::getUserId, keyword)
//                        .select(SocialSecurity::getSocialSecurityNotes, SocialSecurity::getSocialSecurityBase, SocialSecurity::getSocialSecurityType, SocialSecurity::getEnterpriseProportion,
//                                SocialSecurity::getHouseholdRegistration, SocialSecurity::getHouseholdRegistrationType, SocialSecurity::getEnterpriseProvidentFundPayment,SocialSecurity::getProvidentFundBase
//                                ,SocialSecurity::getLastModifyTime,SocialSecurity::getPersonalProportion, SocialSecurity::getPersonalProvidentFundPayment
//                                ,SocialSecurity::getProvidentFundCityId,SocialSecurity::getParticipatingInTheCityId,SocialSecurity::getProvidentFundNotes,SocialSecurity::getIndustrialInjuryRatio)
//        );
//
//        Page<SocialSecurityVO> socialSecurityVOPage = socialSecurityConverter.entityPage(socialSecurityPage);
//
//
//        return socialSecurityVOPage;
    }



